Array.prototype.myFlat = function(num) {
    num = num || 'infinity'
    let n = 1
   const isTypeArray = Array.isArray(this)
   let target = [...this]
   const reduce = (arr)=>{
     return arr.reduce((pre,next)=>{
        return pre.concat(next)
     },[])
   }
   if(isTypeArray){
      while(num !== 'infinity' ? (n <= num && target.some(item => Array.isArray(item))) : target.some(item => Array.isArray(item))){
       target = reduce(target)
       n++
      }
   }
   return target
}
const arr = [1,2,3,4,[5,6,[7,8,[9,10]]]]
console.log(arr.myFlat(100))